<?php 
	// 验证用户是否登录
	require_once 'session-check.php';
	$user = $_SESSION['login_user'];
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>站点管理-管理评论</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link rel="stylesheet" type="text/css" href="../style/admin.css"/>
	</head>
	<body>
		<div class="head">
			站点后台管理  [<a href=".." style="font-color:white">返回站点</a>]
		</div>
		<div class="userinfo">
		当前登录用户:
		<?php 
			echo $user;
			echo ' [<a href="user-action.php?action=logout">注销登陆</a>]';
			echo ' [<a href="user-admin.php">修改密码</a>]';
		?>
		</div>
		<div class="container">
			<div class="left">
				<h1>功能列表</h1>
				<ul>
					<li><a href="user-admin.php">管理用户</a></li>
					<li><a href="post-admin.php">管理文章</a></li>
					<li>管理评论</li>
				</ul>
			</div>
			<div class="right">
			<?php
				require_once '../util/dbconnection.php';
				$page1 = $_POST['page1'];
				$page2 = $_POST['page2'];
				$maxcount = -1;
				if( !isset($page1) ){
					$page1 = 0;
				}
				if( !isset($page2) ){
					$page2 = 0;
				}
				connect_db();
				$msg_list = get_feedback( $page1, $maxcount, '', 1);
				$chk_msg_list = get_feedback($page2, $maxcount, '', 2);
				$trash_msg_list = get_feedback($page2, $maxcount, '', 3);
				close_db();
				
				echo "<h1>管理评论--评论列表</h1>";
				echo "<ul>";
				echo "<li>已通过评论</li>";
				echo_msg( $msg_list, 1 );
				echo "<li>待审核评论</li>";
				echo_msg( $chk_msg_list, 2 );
				echo "<li>已删除评论</li>";
				echo_msg( $trash_msg_list, 3 ) ;
				echo "</ul>";
				
				function echo_msg($list, $type){
					echo '<table>';
					echo '<tr><th>序号</th><th>评论人</th><th>邮箱</th><th>电话</th><th>其他</th><th class="lwidth">评论内容</th><th>评论时间</th><th>评论者IP地址</th><th>操作</th></tr>';
					for( $i=0; $i<count($list);$i++ ){
						$row = $list[$i];
						echo "<tr>";
						echo "<td>".($i+1)."</td>";
						echo "<td>".$row['msger_name']."</td>";
						echo "<td>".$row['msger_mail']."</td>";
						echo "<td>".$row['msger_phone']."</td>";
						echo "<td>".$row['msger_other']."</td>";
						echo "<td>".$row['msg_content']."</td>";
						echo "<td>".$row['msg_date']."</td>"; 
						echo "<td>".$row['msger_ip']."</td>";
						echo '<td>';
						if( $type == 2 ){
							echo '<a href="feedback-action.php?action=pass&id='.$row['id'].'">通过</a>';
							echo "&nbsp;&nbsp;";
						}else if( $type == 3 ){
							echo '<a href="feedback-action.php?action=destroy&id='.$row['id'].'">彻底删除</a>'; 
							echo "&nbsp;&nbsp;";
							echo '<a href="feedback-action.php?action=pass&id='.$row['id'].'">恢复</a>';
							echo "&nbsp;&nbsp;";
						}
						echo '<a href="feedback-action.php?action=del&id='.$row['id'].'">删除</a>';
						echo '</td>';
						echo "</tr>";
					}
					echo "</table>";
				}
			?>
			</div>
		</div>	
	</body>
</html>

